#pragma once
#include <iostream>
#include <functional>
#include <string.h>
#include <thread>

typedef std::function<void (void *param, const uint8_t* data, uint32_t len)> PROCESS_CALLBACK;

class ProrocolBase
{

public:
    ProrocolBase(uint32_t maxBuffSize);
    virtual ~ProrocolBase();

    void addCallBack(PROCESS_CALLBACK cb, void* param);  //注册回调数据处理回调

    // int start();

    //数据打包
    virtual const uint8_t* packageBuffer(const uint8_t* buf, uint32_t inlen, int32_t& outlen) = 0;
    int pushBuffer(const uint8_t *buf, int32_t len);
    uint32_t getRecvOffset() const{ return recv_offset_;};
    uint8_t* getRxbuf(){ return rx_buffer_;};
    uint32_t getBuffSize() const{ return buff_size_;};
    void setRecvOffset(uint32_t offset) { recv_offset_ = offset;};
private:
    /* data */
    uint32_t recv_offset_;
    uint8_t* rx_buffer_;
    uint32_t buff_size_;

    // bool process_flag_;
    // std::shared_ptr<std::thread> data_process_thread_;
    // void data_process_loop();
    
    void* param_;
    PROCESS_CALLBACK package_data_callBack_;


    virtual int pushByte(uint8_t point) = 0;

};


